package netty.iosocket;

import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/11/18 0018
 * Time: 下午 9:15
 * To change this template use File | Settings | File Templates.
 */
public class ClientSocketTest {

    public static void main(String[] args) throws IOException {

        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    Socket socket = null;
                    try {
                        socket = new Socket("127.0.0.1",8080);
                        System.out.println("xxxxxxxxxxxxx");
                        socket.getOutputStream().write(("我是客户端_").getBytes("UTF-8"));
                        byte[] bytes = new byte[1024];
                        socket.getInputStream().read(bytes);
                        System.out.println("接受服务端消息:"+new String(bytes));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }

        });
    }

        executorService.shutdown();
        while (!executorService.isTerminated()){

        }
    }
}








